#ifndef __VIRTUAL_DEVICE_H__
#define __VIRTUAL_DEVICE_H__

#include <linux/blkdev.h>
#include <linux/blk-mq.h>

typedef struct tag_clone_bio clone_bio_t;
typedef struct tag_device_request device_request_t;
typedef struct tag_virtual_device virtual_device_t;

struct tag_virtual_device {
    int minor;
	struct gendisk *disk;
    struct block_device *dev_block;
	struct request_queue *dev_queue;
	struct bio_set dev_bio_set;
	struct blk_mq_tag_set dev_tag_set;
};

struct tag_device_request {
	blk_status_t error;
	virtual_device_t *dev;
	struct request *clone_req;
	struct request *origin_req;
	unsigned int n_sectors;
	unsigned int completed;
};

struct tag_clone_bio {
    device_request_t *req;
    struct bio *origin;
    struct bio clone;
};

int init_device_queue(virtual_device_t *device);
void exit_device_queue(virtual_device_t *device);
virtual_device_t *create_virtual_device(struct block_device *dev_block);
int delete_virtual_device(virtual_device_t *device);
#endif
